package com.wswy.wzcx.ui.main.home;

import android.support.annotation.Nullable;
import com.che.common.map.LocationModel;
import com.che.libcommon.utils.RxBus;
import com.che.libcommon.utils.TypeUtils;
import com.che.libcommon.utils.optional.Optional;
import com.google.gson.reflect.TypeToken;
import com.wswy.wzcx.model.WZCity;
import com.wswy.wzcx.model.license.UserCarInfo;
import com.wswy.wzcx.model.weather.WeatherModel;
import com.wswy.wzcx.module.InternalMsgCode;
import com.wswy.wzcx.module.core.BasePresenter;
import io.reactivex.internal.operators.observable.ObserverResourceWrapper;
import io.reactivex.observers.ResourceObserver;
import java.util.Collections;
import java.util.List;

class BaseHomePresenter extends BasePresenter{

  @Override
  protected void registerObservers() {
    super.registerObservers();
    ResourceObserver<WZCity> locObserver = new ResourceObserver<WZCity>() {
      @Override
      public void onNext(WZCity locationModel) {
        onGetLocation(locationModel);
      }

      @Override
      public void onError(Throwable e) {

      }

      @Override
      public void onComplete() {

      }
    };


    ResourceObserver<UserCarInfo> userCarInfoObserver = new ResourceObserver<UserCarInfo>() {
      @Override
      public void onNext(UserCarInfo userCarInfo) {
        onUserCarInfoUpdate(userCarInfo);
      }

      @Override
      public void onError(Throwable e) {

      }

      @Override
      public void onComplete() {

      }
    };

    ResourceObserver<UserCarInfo> userCarExtendUpdateObserver = new ResourceObserver<UserCarInfo>() {
      @Override
      public void onNext(UserCarInfo userCarInfo) {
        onUserCarInfoUpdate(userCarInfo);
      }

      @Override
      public void onError(Throwable e) {

      }

      @Override
      public void onComplete() {

      }
    };

    ResourceObserver<UserCarInfo> userCarDeleteObserver = new ResourceObserver<UserCarInfo>() {
      @Override
      public void onNext(UserCarInfo userCarInfo) {
        onDeleteCar(userCarInfo.id);
      }

      @Override
      public void onError(Throwable e) {

      }

      @Override
      public void onComplete() {

      }
    };

    ResourceObserver<List<UserCarInfo>> userMyCarsObserver = new ResourceObserver<List<UserCarInfo>>() {
      @Override
      public void onNext(List<UserCarInfo> mycars) {
        onMyCars(mycars);
      }

      @Override
      public void onError(Throwable e) {

      }

      @Override
      public void onComplete() {

      }
    };

    RxBus.getDefault().toObservableWithCode(InternalMsgCode.CODE_GET_LOCATION, WZCity.class)
        .subscribe(locObserver);

    RxBus.getDefault().toObservableWithCode(InternalMsgCode.CODE_UPDATE_EXTEND,
        UserCarInfo.class)
        .subscribe(userCarExtendUpdateObserver);

    RxBus.getDefault().toObservableWithCode(InternalMsgCode.CODE_ADD_UPDATE,
        UserCarInfo.class)
        .subscribe(userCarInfoObserver);

    RxBus.getDefault().toObservableWithCode(InternalMsgCode.CODE_DELETE,UserCarInfo.class)
        .subscribe(userCarDeleteObserver);

    RxBus.getDefault().toObservableWithCode(InternalMsgCode.CODE_UPDATE_CARS,
        new TypeToken<List<UserCarInfo>>(){}.getRawType());


    disposables.add(userCarExtendUpdateObserver);
    disposables.add(locObserver);
//    disposables.add(weatherObserver);
    disposables.add(userCarInfoObserver);
    disposables.add(userCarDeleteObserver);
    disposables.add(userMyCarsObserver);

  }




  protected void onGetLocation(WZCity locationModel){

  }

//  protected void onWeatherUpdate(WeatherModel weatherModel){
//
//  }

  protected void onUserCarInfoUpdate(@Nullable UserCarInfo userCarInfo){

  }

  protected void onDeleteCar(int carId){

  }

  protected void onMyCars(List<UserCarInfo> mycars){

  }

}
